package com.sillyhat.optimize.chapter.two.AvoidNewInstance.main;

import com.sillyhat.optimize.chapter.two.AvoidNewInstance.error.AvoidNewInstanceError;
import com.sillyhat.optimize.chapter.two.AvoidNewInstance.success.AvoidNewInstanceSuccess;

import java.util.Date;

/**
 * AvoidNewInstanceMain
 * 2.5  避免创建不必要的对象
 * @author 徐士宽
 * @date 2017/1/13 11:15
 */
public class AvoidNewInstanceMain {

    public static void main(String[] args) {
        long startTimeError = System.nanoTime();
        for (int i = 0; i < 1000; i++) {
            new AvoidNewInstanceError().isBabyBoomer(new Date(), 2015, 2018);
        }
        long endTimeError = System.nanoTime();
        System.out.println("总执行时间：" + (endTimeError - startTimeError));

        long startTimeSuccess = System.nanoTime();
        for (int i = 0; i < 1000; i++) {
            new AvoidNewInstanceSuccess().isBabyBoomer(new Date());
        }
        long endTimeSuccess = System.nanoTime();
        System.out.println("总执行时间：" + (endTimeSuccess - startTimeSuccess));
    }

}